// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------
// Modification history:
// feature: Unified Transport Abstraction Layer Unified Transport Abstraction Layer
// ------------------------------------------------------------------

#ifndef INCLUDE_VBS_TRANSPORT_TCPTRANSPORTDESCRIPTOR_H_
#define INCLUDE_VBS_TRANSPORT_TCPTRANSPORTDESCRIPTOR_H_

#include <transport/SocketTransportDescriptor.h>
#include <transport/TCPHeader.hpp>
//#include <deps/ertps_dll.h>
#include <iostream>

namespace vbs {
namespace transport {

/**
 * TCP Transport configuration
 *
 * - \c listening_ports: list of ports to listen as server.
 *
 * - \c keep_alive_frequency_ms: frequency of RTCP keep alive requests (in ms).
 *
 * - \c keep_alive_timeout_ms: time since sending the last keep alive request to consider a
 * connection as broken (in ms).
 *
 * - \c max_logical_port: maximum number of logical ports to try during RTCP negotiation.
 *
 * - \c logical_port_range: maximum number of logical ports per request to try during RTCP
 * negotiation.
 *
 * - \c logical_port_increment: increment between logical ports to try during RTCP negotiation.
 *
 * - \c enable_tcp_nodelay: enables the TCP_NODELAY socket option.
 *
 * - \c calculate_crc: true to calculate and send CRC on message headers.
 *
 * - \c check_crc: true to check the CRC of incoming message headers.
 *
 * - \c apply_security: true to use TLS (Transport Layer Security).
 *
 * - \c tls_config: Configuration for TLS.
 *
 * @ingroup TRANSPORT_MODULE
 */
struct TCPTransportDescriptor : public SocketTransportDescriptor {
    /**
     * TLS Configuration
     *
     * - \c password: password of the \c private_key_file or \c rsa_private_key_file.
     *
     * - \c private_key_file: path to the private key certificate file.
     *
     * - \c rsa_private_key_file: path to the private key RSA certificate file.
     *
     * - \c cert_chain_file: path to the public certificate chain file.
     *
     * - \c tmp_dh_file: path to the Diffie-Hellman parameters file.
     *
     * - \c verify_file: path to the CA (Certification-Authority) file.
     *
     * - \c verify_mode: establishes the verification mode mask.
     *
     * - \c options: establishes the SSL Context options mask.
     *
     * - \c verify_paths: paths where the system will look for verification files.
     *
     * - \c default_verify_path: look for verification files on the default paths.
     *
     * - \c handshake_role: role that the transport will take on handshaking.
     *
     * - \c server_name: server name or host name required in case Server Name Indication (SNI) is
     * used.
     *
     */

    //! List of ports to listen as server
    std::vector<uint16_t> listening_ports;

    RTCPHeader rtcp_header_;

    // EDDS_TODO_BEFORE(3, 0, "Eliminate tcp_negotiation_timeout, variable not in use.")
    uint32_t tcp_negotiation_timeout;
    //! Enables the TCP_NODELAY socket option
    bool enable_tcp_nodelay;

    // EDDS_TODO_BEFORE(3, 0, "Eliminate wait_for_tcp_negotiation, variable not in use.")
    bool wait_for_tcp_negotiation;

    //! Add listener port to the listening_ports list
    void add_listener_port(uint16_t port) { listening_ports.push_back(port); }

    void set_rtcp_header(const RTCPHeader& rtcp_header) { rtcp_header_ = rtcp_header; }

    //! Constructor
    RTPS_DllAPI TCPTransportDescriptor();

    //! Copy constructor
    RTPS_DllAPI TCPTransportDescriptor(const TCPTransportDescriptor& t);

    //! Copy assignment
    RTPS_DllAPI TCPTransportDescriptor& operator=(const TCPTransportDescriptor& t);

    //! Destructor
    virtual ~TCPTransportDescriptor() = default;

    //! Comparison operator
    RTPS_DllAPI bool operator==(const TCPTransportDescriptor& t) const;
};

}  // namespace transport
}  // namespace vbs

#endif  // INCLUDE_VBS_TRANSPORT_TCPTRANSPORTDESCRIPTOR_H_
